package com.lifeng.config;

import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.LocalDate;
import java.time.LocalTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;

/**
 * Created by lifeng on 2019/10/30.
 * 此类可以没有 直接在yml中配置规则
 */
@Configuration
public class GatewayConfig {

    @Bean
    public RouteLocator myRoutes(RouteLocatorBuilder builder) {
        return builder.routes()
                /* s开头的添加 header 并转发到baidu上*/
                /*.route(p -> p
                        .path("/s")
                        .filters(f -> f.addRequestHeader("Hello", "World"))
                        .uri("https://www.baidu.com")
                )*/
                /* host 将转发到uri上*/
                /*.route(p -> p
                        .host("127.0.0.1:8127")
                        .uri("https://www.baidu.com")
                )*/
                /* 在这个配置时间之后才能被路由*/
                /*.route(p -> p
                        .after(ZonedDateTime.of(2019,10,30,15,0,0,0, ZoneId.systemDefault()))
                        .uri("https://www.liaoxuefeng.com/")
                )*/
                /* 请求带有 cookies 的将被转发*/
                /*.route(p -> p
                        .cookie("myname","lifeng")
                        .uri("https://www.liaoxuefeng.com/")
                )*/
                .build();
    }
}
